package com.wang.web.controllers;

import javax.inject.Inject;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.web.ConnectController;
import org.springframework.social.connect.web.ProviderSignInController;
import org.springframework.social.connect.web.SignInAdapter;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@PropertySource(value="classpath:social.properties")
@EnableWebMvc
public class ServletConfig {
	
	@Inject
	private Environment environment;
	@Inject
	private ConnectionFactoryLocator connectionFactoryLocator;
	@Inject
	private ConnectionRepository connectionRepository;
	@Inject
	private UsersConnectionRepository usersConnectionRepository;
	@Inject
	private SignInAdapter signInAdapter;
	
	@Bean
    public ConnectController connectController() {
		ConnectController controller = new ConnectController(connectionFactoryLocator, connectionRepository);
		controller.setApplicationUrl(environment.getProperty("social.application.url"));
		
		return controller;
    }
	
	@Bean
	public ProviderSignInController providerSignInController() {
		ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, signInAdapter);
		controller.setApplicationUrl(environment.getProperty("application.url"));
		controller.setSignUpUrl("/signup");
		return controller;
	}
}
